﻿using System.Linq;
using System.Text;
using TSharp.Core.Util;
using System.Diagnostics;
using TSharp.Core.Net;
[assembly: TSharp.Core.Osgi.RegTypeInit(typeof(Test))]

namespace TSharp.Core.Net
{

    /// <summary>
    /// 
    /// </summary>
    public class Node
    {
        /// <summary>
        /// Gets or sets the URL.
        /// </summary>
        /// <value>
        /// The URL.
        /// </value>
        public ParameterizedUri Url { get; set; }
        /// <summary>
        /// Gets or sets the method.
        /// </summary>
        /// <value>
        /// The method.
        /// </value>
        public HttpMethod Method { get; set; }
        /// <summary>
        /// Submits the data use the specifed session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public virtual byte[] SubmitData(HttpWebClient session)
        {
            if (Method == HttpMethod.Post)
            {
                return session.UploadValues(this.Url.AsUri, null, this.Url.Queries);
            }
            else
            {
                return session.DownloadData(this.Url.ToString());
            }
        }
        /// <summary>
        /// Submit use the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public virtual string Submit(HttpWebClient session)
        {
            var bytes = SubmitData(session);
            return session.Encoding.GetString(bytes);
        }

    }
}
